
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="../../script/mui.min.js"></script>
		<link href="../../css/mui.min.css" rel="stylesheet"/>
		<link rel="stylesheet" type="text/css" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/api.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<style type="text/css">
			html{
				height: 100%;
			}
			body{
				height: 100%;
			}
			.sxtype0{
			    font-size:14px;
			    float:right;
			    margin-right:37px;
			    margin-top:9px;
			    width:60px;
			    height:25px;
			    text-align:center;			  
			    color: #18B4ED;
			    border:solid 1px #18B4ED;
			    padding-top: 2px;
                border-radius: 5px;
			}
			.sxtype1{
                font-size:14px;
                float:right;
                margin-right:37px;
                margin-top:9px;
                width:60px;
                height:25px;
                text-align:center;
                color:#14BB8F;               
                border:solid 1px #14BB8F;
                padding-top: 2px;
                border-radius: 5px;
            }
            .sxtype2{
                font-size:14px;
                float:right;
                margin-right:37px;
                margin-top:9px;
                width:60px;
                height:25px;
                text-align:center;
                color:#F45849;
                border:solid 1px #F45849;
                padding-top: 2px;
                border-radius: 5px;
            }
             .sxtype3{
                font-size:14px;
                float:right;
                margin-right:37px;
                margin-top:9px;
                width:60px;
                height:25px;
                text-align:center;
                color:#979797;
                border:solid 1px #979797;
                 padding-top: 2px;
                border-radius: 5px;
            }
			::-webkit-scrollbar{width:0px}
			.checkbox_comp_info{
				padding-right: 30px;
			}
		</style>
	</head>
	<body>
	<div class="changeState">
		<div class="wraptop">

			<div class="mui-input-row mui-checkbox select_num" style="background-color: #f0f0f0;" hidden="hidden">
				  <label class="base_tag_font base_light_gray " style="color: #222222">
				  	学生  已选择<span id="studentNum">0</span>人
				  </label>
				  <input name="checkbox" value="Item 0" type="checkbox" id="checkdeAll">
			</div>
		</div>
		
	
		<div class="contents" style="margin-top: 40px;margin-bottom: 50px">
			<ul class="mui-table-view " id="checkboxes">
				<!-- <li class="mui-table-view-cell mui-checkbox mui-media">
					<a href="javascript:;">
						<img class="mui-media-object mui-pull-left" src="../image/icon_man.png">
						<div class="mui-media-body">
							( ‵o′)凸
							<span class="">琦玉</span>           	
							<p class="mui-ellipsis checkbox_comp_info">实习单位：天狼星绿水湖布门岛藏仙洞长史祠坐上真人刘能</p>
						</div>
					</a>
					<input dataindex="" name="checkbox2" value="Item 1" type="checkbox">
				</li> -->
			</ul>
			<div class="noSign" hidden="hidden" id="noData">
				<img src="../../image/icon_img.png" width="60%">
				<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
			</div>
			<div class="loadFailure" hidden="hidden" id="noNet">
				<img src="../../image/icon_img01.png" width="60%">
				<p class="" >
					数据加载失败
				</p>
				<p>
					请检查您的网络
				</p>
				<button type="button" class="mui-btn mui-btn-outlined" onclick="setupType()">
					重新加载
				</button>
			</div>
		</div>
		<div class="bottom_btn" hidden="hidden">
			<button type="button" class="mui-btn btn_submit" id="submit" >提交</button>
		</div>
	</div>	
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script>
	var classid = '';
	var currentStudents;
	var pageType;
	apiready = function(){
		setupType();
		prepareData();
	}
	function setupType(){
		var pageParam = api.pageParam;
		pageType = pageParam.type;
			loadCompanyStu(pageParam.cid);
		

	}
	//加载企业实习学生
	function loadCompanyStu(cid){
	
		showProgressFrame();
		var params = {
			cid : cid,
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjid'),
		};
//	 alert(JSON.stringify( params));
		cfnetppPOST(urlCompanyStuList,params,true,function(data, status){
//		 alert(JSON.stringify(data));
			api.hideProgress();
			if (status == 'success') {
				if (data.status == 1) {
					var students = data.json;
					if (students.constructor == Array && students.length > 0) {
					    $(".select_num").show();
				
						$(".bottom_btn").show();
						$('#noData').hide();
						$('#noNet').hide();
						currentStudents = students;
						var studentsHtmlStr = '';
						for (var i = 0; i < students.length; i++) {
							var studentData = students[i];
							studentsHtmlStr += studentHtmlString(studentData, i);
						}
						$('#checkboxes').html(studentsHtmlStr);
						setupCheckBoxes();
					}else{
						$('#noData').show();
						$('#noNet').hide();

					}
				}else{
					$('#noData').show();
					$('#noNet').hide();

				}
			}else{
				$('#noData').hide();
				$('#noNet').show();
				
			}
		});
	}

	//获取班级学生列表
	function grabClassStudentsData(){
		showProgressFrame();
		var params = {
			class_id: classid,
			jid: $api.getStorage('cfnetppjid')
		};
		cfnetppPOST(
		urlStudentlist,
		params,
		true,
		function(data, status){
			api.hideProgress();
			if (status == 'success') {
				if (data.status == 1) {
					var students = data.json;
					if (students.constructor == Array && students.length > 0) {
						$('#noData').hide();
						$('#noNet').hide();
						currentStudents = students;
						var studentsHtmlStr = '';
						for (var i = 0; i < students.length; i++) {
							var studentData = students[i];
							studentsHtmlStr += studentHtmlString(studentData, i);
						}
						$('#checkboxes').html(studentsHtmlStr);
						setupCheckBoxes();
					}else{
						$('#noData').show();
						$('#noNet').hide();
						api.toast({
						    msg: '暂无数据'
						});
					}
				}else{
					$('#noData').show();
					$('#noNet').hide();
					api.toast({
					    msg: '获取学生列表失败'
					});
				}
			}else{
				$('#noData').hide();
				$('#noNet').show();
				api.toast({
				    msg: '获取学生列表失败'
				});
			}
		});
	}
	function setupCheckBoxes(){
		$("#checkdeAll").prop("checked",false);
		$("#studentNum").text('0');
		//单选
		$("#checkboxes .mui-table-view-cell").unbind('click');
		$("#checkboxes .mui-table-view-cell").click(function(){
			var len = $("#checkboxes input:checkbox:checked").length;//选中个数
			if(len<$("#checkboxes input[type=checkbox]").length){
				$("#checkdeAll").prop("checked",false);
			}
			$("#studentNum").text(len)// 显示选中个数
		});
	}
	function prepareData() {

		//全选
		$("#checkdeAll").click(function(){
			if(this.checked){
				$("#checkboxes input[type=checkbox]").prop("checked",true);
			}else {	
				$("#checkboxes input[type=checkbox]").prop("checked",false);
			}
			var len = $("#checkboxes input:checkbox:checked").length;//选中的个数 
			$("#studentNum").text(len)// 显示选中个数
		})
		//提交绑定事件
		$('#submit').click(function() {
    		var dataindexs = getUserIds();
    		if (dataindexs == null || dataindexs == '' || dataindexs == undefined || dataindexs.constructor != Array  || dataindexs.length == 0) {
    			api.toast({
    			    msg: '请选择学生后再提交'
    			});
    			return;
    		}
    		var selectedStuIds = new Array();
    		var selectedStuDatas = new Array();
    		for (var i = 0; i < dataindexs.length; i++) {
    			var index = parseInt(dataindexs[i]);
    			var studentData = currentStudents[index];
    			var stuId = parseInt(studentData.uid);
    			var stuName = studentData.rename1;
    			selectedStuIds.push(stuId);
    			selectedStuDatas.push({
    				studentid: stuId,
    				studentname: stuName
    			});
    		}
    		
    			api.sendEvent({
    			    name: 'selectStudentNotifi',
    			    extra: {
    			        stuArr : selectedStuDatas
    			    }
    			});
    			api.closeWin();
    		
   		});
	}
	function getUserIds(){
		var $value = [];
		$('#checkboxes').find('input').each(function(i){
	        if(this.checked==true){
	            $value.push($(this).attr('dataindex'));
	        }
	    });
		return $value;
	}
	function studentHtmlString(data,i){
		var userid = data.uid;
		var uname = data.rename1;
		var corpname = data.corp_name;
		var ustatus;
		var ustatusStr = '';
		var ustatusClass = '';
		if (pageType == 0) {
			ustatus = data.is;
			if (ustatus == 0) {
				ustatusStr = '未实习';
				ustatusClass = 'sxtype0';
			}else if(ustatus == 1){
				ustatusStr = '实习中';
				ustatusClass = 'sxtype1';
			}else if(ustatus == 2){
				ustatusStr = '实习结束';
				ustatusClass = 'sxtype3';
			}else if(ustatus == 3){
				ustatusStr = '未结业';
				ustatusClass = 'sxtype2';
			}else if(ustatus == 4){
				ustatusStr = '已结业';
				ustatusClass = 'sxtype2';
			}
		}
		if(corpname == null || typeof(corpname) == undefined){
			corpname = '暂无实习单位';
		}
		return '<li class="mui-table-view-cell mui-checkbox mui-media">'+
					'<a href="javascript:;">'+
						'<img class="mui-media-object mui-pull-left" src="../../image/icon_man.png">'+
						'<div class="mui-media-body">'+
							uname+
							// '<img class="gender" src="../image/icon_boy.png" alt="">	'+
							'<span class="'+ustatusClass+'">'+ustatusStr+'</span>'+            	
							'<p class="mui-ellipsis checkbox_comp_info">实习单位：'+corpname+'</p>'+
						'</div>'+
					'</a>'+
					'<input dataindex="'+i+'" name="checkbox2" value="Item 1" type="checkbox">'+
				'</li>';
	}
	
    function showProgressFrame(){
    	api.showProgress({
    	    style: 'default',
    	    animationType: 'fade',
    	    title: '加载中...',
    	    text: '请稍候...',
    	    modal: false
    	});
    }
	</script>
	</body>
</html>
